package cn.com.bluemoon.bd.flink.source;

import org.apache.flink.streaming.api.functions.source.RichSourceFunction;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class BaseDataSource extends RichSourceFunction<String> {

    private int minute;

    public BaseDataSource(int minute) {
        this.minute = minute;
    }

    @Override
    public void run(SourceContext ctx) throws Exception {
        while (true) {
            ctx.collect(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            Thread.sleep(minute * 60 * 1000);
        }
    }

    @Override
    public void cancel() {

    }
}
